package ru.ipo.dces.plugins.admin;

import ru.ipo.dces.client.Controller;
import ru.ipo.dces.client.Localization;
import ru.ipo.dces.pluginapi.Plugin;
import ru.ipo.dces.pluginapi.PluginEnvironment;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by IntelliJ IDEA.
 * User: ilya
 * Date: 30.03.11
 * Time: 17:00
 */
public class UserHistoryPlugin implements Plugin {

    private UserHistoryDisplay display = new UserHistoryDisplay();
    private JPanel pluginPanel;

    public UserHistoryPlugin(PluginEnvironment environment) {
        environment.setTitle(Localization.getAdminPluginName(UserHistoryPlugin.class));

        display.setUserID(Controller.getContestConnection().getUser().userID);

        JButton refreshButton = new JButton("Обновить");

        pluginPanel = new JPanel();
        pluginPanel.setLayout(new BorderLayout());
        pluginPanel.add(display, BorderLayout.CENTER);
        pluginPanel.add(refreshButton, BorderLayout.SOUTH);

        refreshButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                display.updateInfo();
            }
        });
    }

    public JPanel getPanel() {
        return pluginPanel;
    }

    public void activate() {
        display.updateInfo();
    }

    public void deactivate() {
        //do nothing
    }
}
